diff options
Diffstat (limited to 'app/src/routes/assignments/[assignmentId]/+page.server.ts')
-rw-r--r-- | app/src/routes/assignments/[assignmentId]/+page.server.ts | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/app/src/routes/assignments/[assignmentId]/+page.server.ts b/app/src/routes/assignments/[assignmentId]/+page.server.ts index 566dcd9..280c5bd 100644 --- a/app/src/routes/assignments/[assignmentId]/+page.server.ts +++ b/app/src/routes/assignments/[assignmentId]/+page.server.ts @@ -1,5 +1,5 @@ -import { getAssignmentAndCemetaryById } from "$lib/server/assignments"; -import type { PageServerLoad } from "./$types"; +import { finishAssignment, getAssignmentAndCemetaryById } from "$lib/server/assignments"; +import type { PageServerLoad, Actions } from "./$types"; import { error, redirect } from "@sveltejs/kit"; export const load = (async ({ params, url, locals }) => { @@ -25,3 +25,29 @@ export const load = (async ({ params, url, locals }) => { cemetaryPlot, }; }) satisfies PageServerLoad; + +export const actions = { + // FIXME: Skipped input validation. + // FIXME: Is 'load' action run (wrt. authentication)? + finish: async ({ params, request, locals }) => { + const formData = await request.formData(); + const imageFiles = formData.getAll("images") as File[]; + const note = (formData.get("note") as string | null) ?? undefined; + + // Read image files in parallel. + const images = await Promise.all( + imageFiles.map(async (f) => ({ + name: f.name, + bytes: new Uint8Array(await f.arrayBuffer()), + })), + ); + + await finishAssignment(locals.dbConn, locals.s3Client, { + images, + note, + assignmentId: +params.assignmentId, // We have parsing at home... + }); + + return { success: true }; + }, +} satisfies Actions; |